package com.tip;

import java.lang.reflect.Field;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.alibaba.roma.web.ioc.ContextBeanProvider;
import com.tip.dal.dao.ITipDAO;
import com.tip.search.SearchModel;

public class WebContextBeanProvider implements ContextBeanProvider {

    private static ApplicationContext context = new ClassPathXmlApplicationContext(
                                                                                   new String[] { "classpath:/META-INF/spring/bean/*.xml" });

    public Object getBean(Field field) {
        return context.getBean(field.getName());
    }

    public Object getBean(String name) {
        return context.getBean(name);
    }

    public static Object getBeanObject(String name) {
        return context.getBean(name);
    }
    
    public static SearchModel getSearchModel() {
        Object obj = context.getBean("searchModel");
        if (obj instanceof SearchModel)
        {
        	return (SearchModel)obj;
        }
        return null;
    }
    
    public static ITipDAO getTipDAO() {
        Object obj = context.getBean("tipDAO");
        if (obj instanceof ITipDAO)
        {
        	return (ITipDAO)obj;
        }
        return null;
    }
}
